package com.top.horizon.th1804app.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.top.horizon.th1804app.utils.ToastUitl;
import com.top.horizon.th1804app.view.CustomDialog;

public abstract class BaseFragment extends Fragment implements CustomDialog.OnClickChildVIewListener {
    protected View rootView;
    protected CustomDialog customDialog;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(getLayoutResource(), container, false);
            customDialog = new CustomDialog(getContext(), 0);
            initView();
            initData();
        }
        return rootView;
    }

    /**
     * 显示选择对话框
     *
     * @param layoutId
     */
    public void showChooseDialog(int layoutId) {
//        if (customDialog == null)
        customDialog.setLayout(layoutId);
        customDialog.setOnClickChildVIewListener(this);
        customDialog.showDialog();
    }

    public void showDialog(View view) {
        customDialog.setOnClickChildVIewListener(this);
        customDialog.showDialog(view);
    }

    public void dismissDialog() {
        if (customDialog != null)
            customDialog.dismiss();
    }

    /**
     * 显示短时间吐司
     *
     * @param message
     */
    public void showToast(String message) {
        ToastUitl.showToast(getContext(), message);
    }

    /**
     * 显示长时间吐司
     *
     * @param message
     */
    public void showLongToast(String message) {
        ToastUitl.showLongToast(getContext(), message);
    }

    /**
     * 弹出短时间中间显示吐司
     *
     * @param message
     */
    public void showShortCenterToast(String message) {
        ToastUitl.showShortCenterToast(getContext(), message);
    }

    public void showProgressLoadingDialog() {
        BaseActivity activity = (BaseActivity) getActivity();
        activity.showProgressDialog("加载中");
    }

    public void dismissProgressLoadingDialog() {
        BaseActivity activity = (BaseActivity) getActivity();
        activity.hideProressDialog();
    }


    protected abstract int getLayoutResource();

    protected abstract void initView();

    protected abstract void initData();

    @Override
    public void onClickChildView(View view, int mLayoutId) {

    }


}
